package com.saifan.wyy_ov.ui.communitylife;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.saifan.wyy_ov.R;
import com.saifan.wyy_ov.ui.view.SquareImageView;
import com.saifan.wyy_ov.utils.ImgUtil;

import java.util.ArrayList;

/**
 * @author WangLi
 * @date 2015年3月26日 下午5:35:43
 * @Description 评论里面的图片
 * @version V1.0
 */

public class BBSPublisAdapter extends BaseAdapter {
    public ArrayList<String> list;
    public Activity activity;

    public BBSPublisAdapter(ArrayList<String> list, Activity activity) {
        super();
        this.list = list;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return list.size() < 4 ? list.size() + 1 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;

    }

    @Override
    public long getItemId(int position) {
        return position;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            SquareImageView imgview = new SquareImageView(activity);
            convertView = imgview;
            viewHolder = new ViewHolder();
            viewHolder.imgview = imgview;
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (list.size() < 4){
            if (position == 0){
                ImgUtil.DisPlayImg(R.drawable.bbs_uploading_img, viewHolder.imgview, activity);

            } else {
                ImgUtil.DisPlayImgForLocal(list.get(position - 1), viewHolder.imgview, activity);
            }
        } else {
            ImgUtil.DisPlayImgForLocal(list.get(position), viewHolder.imgview, activity);
        }
        return convertView;
    }

    class ViewHolder{
        SquareImageView imgview;
    }

}
